package algorithm.leetcode.simple;

/*
 给定一个排序数组，你需要在 原地 删除重复出现的元素，使得每个元素只出现一次，返回移除后数组的新长度。
 */

/**
 * @author jack.wu
 * @version 1.0
 * @date 2020/9/16
 */
public class Question26 {

    public static void main(String[] args) {
        int[] nums = {1, 1, 1, 2};
        Question26 question = new Question26();
        int i = question.removeDuplicates(nums);
        System.out.println(i);
    }

    public int removeDuplicates(int[] nums) {
        if (nums == null || nums.length == 0) {
            return 0;
        }
        int i = 0;
        for (int j = 1; j < nums.length; j++) {
            if (nums[i] != nums[j]) {
                i++;
                nums[i] = nums[j];
            }
        }
        return i + 1;
    }
}
